static struct addrinfo hints = { 0, AF_INET, SOCK_DGRAM, ... };
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > static struct addrinfo hints = { 0, AF_INET, SOCK_DGRAM, ... };




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    static struct addrinfo hints = { 0, AF_INET, SOCK_DGRAM, ... };  
Alexander Farber


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-22-05 12:50 PM

Hello,

is it ok to statically initialize a struct addrinfo this way:

static struct addrinfo hints =
{ 0, AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0, NULL, 0, NULL};

? I have the following function connecting UDP sockets for a longer
list of hosts and would like to speed it up by getting rid of its
first 4 lines:

int
udp_connect(const char *hname)
{
struct addrinfo         hints, *paihead, *pai;
int                     result, udpfd = -1;

bzero(&hints, sizeof(hints));
hints.ai_family   = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_UDP;

/* resolve the host name and service port */
if ((result = getaddrinfo(hname, "echo", &hints, &paihead)) !=
0) {
die("Can't resolve '%s': %s", hname,
gai_strerror(result));
}

/* create a UDP socket and connect it to the host */
for (pai = paihead; pai != NULL; pai = pai->ai_next) {
if((udpfd = socket(pai->ai_family, pai->ai_socktype,
pai->ai_protocol)) == -1)
continue;
/* connect succeded -> print IP:port and proceed */
if(connect(udpfd, pai->ai_addr, pai->ai_addrlen) == 0)
{
if (debug)
print_address(hname, pai->ai_addr);
break;
}
close(udpfd);
udpfd = -1;
}

freeaddrinfo(paihead);
if (-1 == udpfd)
die("Can't connect a UDP socket to '%s'", hname);

return udpfd;
}

Or is addrinfo an "opaque" kind of structure?

I've looked up its definition in /usr/include/netdb.h
on Linux, HP-UX and OpenBSD and they seem to match...

Regards
Alex






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:50 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register