recvfrom and sockaddr_in.sin_port

Adam (adam@eax.com)
Sun, 8 Jul 2001 12:14:47 -0500 (EST)


This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.

--42009324-1390288157-994612487=:1430
Content-Type: TEXT/PLAIN; charset=US-ASCII

hello,
I'm using recvfrom, and upon return it should fill in
from argument with sockaddr_in data structure. from
ip(7) man page I get that it has format of :

struct sockaddr_in {
sa_family_t sin_family; /* address family: AF_INET */
u_int16_t sin_port; /* port in network byte order*/
struct in_addr sin_addr; /* internet address */
};

for PF_INET type of socket. Now if I run the program the, data in
the from field comes out as:

2 0 0 0 192 168 1 4 61 63 140 200 85 214 2

| | |

AF_INET :2
IP :192.168.1.4

and as show in above example and other repeated test, the port
part is always set to 0. Shouldn't that be set to port number?

on similar token the "padding" part after the IP is always set
to the same pattern. Shouldn't it rather be zeroed, or be
some random data?

I have attached a simple program I used for generating those
results.

-- 
Adam
http://www.eax.com      The Supreme Headquarters of the 32 bit registers

--42009324-1390288157-994612487=:1430 Content-Type: TEXT/x-csrc; name="test.c" Content-Transfer-Encoding: BASE64 Content-ID: <Pine.LNX.4.33.0107081214470.1430@eax.student.umd.edu> Content-Description: Content-Disposition: attachment; filename="test.c"

I2luY2x1ZGUgPHN5cy90eXBlcy5oPg0KI2luY2x1ZGUgPHN5cy9zb2NrZXQu aD4NCiNpbmNsdWRlIDxuZXRpbmV0L2luLmg+DQojaW5jbHVkZSA8bmV0ZGIu aD4NCiNpbmNsdWRlIDxzdGRpby5oPg0KI2luY2x1ZGUgPGVycm5vLmg+DQoj aW5jbHVkZSA8c3RyaW5nLmg+DQojaW5jbHVkZSA8c3RkbGliLmg+DQojaW5j bHVkZSA8Y3R5cGUuaD4NCg0KaW50IG1haW4gKGludCBhcmdjLCBjaGFyICoq YXJndikgew0KDQogIHNpemVfdCBidWZsZW4gPSAxMDI0Ow0KICBjaGFyIGJ1 ZltidWZsZW5dOw0KICBzdH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ZTolaSBwb3J0OiVYIGFk ZHI6JVggXG4iLCANCgkgICAgIGZyb20uc2luX2ZhbWlseSwNCgkgICAgIG50 b2hzKGZyb20uc2luX3BvcnQpLA0KCSAgICAgZnJvbS5zaW5fYWRkci5zX2Fk ZHIpOw0KDQogICAgICBob3N0PWdldGhvc3RieWFkZHIoJihmcm9tLnNpbl9h ZGRyLnNfYWRkciksDQoJCQkgZnJvbWxlbixmcm9tLnNpbl9mYW1pbHkpOw0K DQogICAgICBpZiAoaG9zdCA9PSBOVUxMICkgew0KCXByaW50ZigiZXJyICMg OiAlaSBcbiIsaF9lcnJubyk7DQoJaGVycm9yKCJnZXRob3N0YnlhZGRyKCk6 Iik7DQogICAgICB9DQoNCiAgICAgIHByaW50ZigiaG9zdDogKCIpOw0KDQog ICAgICBwdHIgPSAodW5zaWduZWQgY2hhciopKCYoZnJvbS5zaW5fYWRkci5z X2FkZHIpKTsNCiAgICAgIGZvcihpPTA7aTw0O2krKykgew0KCXByaW50Zigi JWkiLCoocHRyKyspKTsNCglpZiAoaTwzKQ0KCSAgcHJpbnRmKCIuIik7DQog ICAgICB9DQogICAgICANCiAgICAgIGlmIChob3N0ID09IE5VTEwpDQoJcHJp bnRmKCIpIFxuIik7DQogICAgICBlbHNlDQoJcHJpbnRmKCIpICVzIFxuIixo b3N0LT5oX25hbWUpOw0KDQoNCiAgICB9DQoNCg0KICByZXR1cm4gMDsNCg0K fQ0K --42009324-1390288157-994612487=:1430-- - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/