linux - Why the connect() connect the host itself when the argument addr does't assign ip address -


this question has answer here:

the example code follows:

int sockfd = socket(af_inet, sock_stream, 0); struct sockaddr_in addr; bzero(&addr, sizeof(addr)); addr.sin_family = af_inet; addr.sin_port = htons(6666); int len = sizeof(addr); // connect not assign destination ip int ret = connect(sockfd, (struct sockaddr*)&addr, len); ...... 

in fact, if host listen tcp port 6666, connect() connects host in linux.

my problem defines behavior of connect() while destination ip not assigned. @ least, cannot find definition in manual.

someone can help?

bzero(&addr, sizeof(addr)); 

this set addr.sin_addr.s_addr 0.0.0.0.

0.0.0.0 valid address syntax. so, should parse valid wherever ip address in traditional dotted-decimal notation expected. once parsed , converted workable numeric form, value determines happens next.

you can ping 0.0.0.0 check happening.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -