Re: ./EuGTK/GtkEngine.e to Irv

new topic     » goto parent     » topic index » view thread      » older message » newer message

Here's one way to do it without using ifconfig. It creates a UDP socket, multicasts a packet to itself, and returns the from address. No error checking.

include std/dll.e 
include std/machine.e 
include std/socket.e 
 
constant  
    IPPROTO_IP = 0, 
    IPPROTO_UDP = 17, 
    IP_ADD_MEMBERSHIP = 35, 
    setsockopt_ = define_c_func(-1, "setsockopt", {C_INT, C_INT, C_INT, C_POINTER, C_INT}, C_INT) 
     
function inet_address() 
    object sock 
    sequence addr = {228,105,19,77}, saddr = sprintf("%d.%d.%d.%d", addr) 
    integer port = 13025 
    atom mreq = allocate(12) 
 
    sock = sockets:create(AF_INET, SOCK_DGRAM, IPPROTO_UDP) 
    sockets:set_option(sock, SOL_SOCKET, SO_REUSEADDR, 1) 
    sockets:bind(sock, saddr, port) 
    poke(mreq, addr & {0,0,0,0,0,0,0,0}) 
    c_func(setsockopt_, {sock[1], IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq, 12}) 
    free(mreq) 
    sockets:send_to(sock, {0}, saddr, port) 
    addr = sockets:receive_from(sock) 
    sockets:close(sock) 
    return addr[1] 
end function 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu