UNIX Network Programming Volume 1, Third Edition [Electronic resources] : The Sockets Networking API نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

UNIX Network Programming Volume 1, Third Edition [Electronic resources] : The Sockets Networking API - نسخه متنی

Addison Wesley

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید










23.8 Finding an Association ID Given an IP Address


In the recent changes we made to our client in Section 23.7, the client used the association notification to trigger retrieving the list of addresses. This notification was quite convenient since it held the association's identification in the sac_assoc_id field. But, if the application is not tracking association identifications and only has an address of a peer, how can it find an association's identification? In Section 23.10.


Initialize


78 Our function first initializes its sctp_paddrparams structure.


Copy address


9 We copy the address, using the passed length, into the sctp_paddrparams structure.


Call socket option


10 The function now uses the SCTP_PEER_ADDR_PARAMS socket option to request peer address parameters. Note that we use sctp_opt_info, instead of getsockopt, since the SCTP_PEER_ADDR_PARAMS socket option requires copying arguments both into and out of the kernel. This call will return the current heartbeat interval, the maximum number of retransmissions before the SCTP implementation considers the peer address to have failed, and most importantly, the association ID. Note that we do not check the return value, since if the call fails, we want to return 0.

Figure 23.13 Translate an address to an association ID.

sctp/sctp_addr_to_associd.c


1 #include "unp.h"
2 sctp_assoc_t
3 sctp_address_to_associd(int sock_fd, struct sockaddr *sa, socklen_t salen)
4 {
5 struct sctp_paddrparams sp;
6 int siz;
7 siz = sizeof(struct sctp_paddrparams);
8 bzero(&sp, siz);
9 memcpy(&sp.spp_address, sa, salen);
10 sctp_opt_info(sock_fd, 0, SCTP_PEER_ADDR_PARAMS, &sp, &siz);
11 return (sp.spp_assoc_id);
12 }

11 The function returns the association ID to the caller. Note that if the call fails, the earlier clearing of the structure will assure our caller of getting a 0 as the returned association ID. An association ID of 0 is not allowed and is used to indicate no association by the SCTP implementation as well.


/ 450