A socket address in a NetBIOS address family is composed of the six fields in the following sockaddr_nb structure: length, address family, address type, a reserved field, adapter number, and NetBIOS name. This structure is located in the <NETNB\NB.H> header file:
struct sockaddr_nb { u_char snb_len; /* sizeof(struct sockaddr_nb) */ u_char snb_family; /* AF_NETBIOS */ short snb_type; /* 0:unique or 1:group */ char snb_nbnetid[NB_NETIDLEN]; /* NetBIOS netid */ char snb_name[NAMELEN]; /* NetBIOS name */ }
The length field (snb_len) is set to sizeof(struct sockaddr_nb).
The family field (snb_family) is set to AF_NETBIOS or AF_NB.
The address type field (snb_type) is used to specify the name as either a unique (NB_UNIQUE) or a group (NB_GROUP) name.
The network identifier field (sub_netid) is used by the protocol stack to contain the NetBIOS netid, which is the logical adapter number that the name is associated with.
The name field (snb_name) contains the 16-byte NetBIOS name, and is used as is.
If a connect() socket call is received without an explicit bind() call, an implicit bind is automatically performed. The application can use any name, and a unique NetBIOS name is generated by the system. A NetBIOS name is generated for this socket by converting the 6-byte MAC address to an ASCII hex string, and postpended with a 2-byte number that increments after each use. You can retrieve the NetBIOS name by using the getsockname() call.
Note that for the NetBIOS domain, more than one socket can be bound to the same local address to establish multiple connections to one or more remote destinations. To enable this feature, the socket option SO_REUSEADDR must be set (see setsockopt()). In addition, you can bind more than one address to the same adapter.