tools/usb/usbip/src/usbip_network.c
Source file repositories/reference/linux-study-clean/tools/usb/usbip/src/usbip_network.c
File Facts
- System
- Linux kernel
- Corpus path
tools/usb/usbip/src/usbip_network.c- Extension
.c- Size
- 5998 bytes
- Lines
- 304
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sys/socket.hstring.harpa/inet.hnetdb.hnetinet/tcp.hunistd.htcpd.husbip_common.husbip_network.h
Detected Declarations
function usbip_setup_port_numberfunction usbip_net_pack_uint32_tfunction usbip_net_pack_uint16_tfunction usbip_net_pack_usb_devicefunction usbip_net_pack_usb_interfacefunction usbip_net_recvfunction usbip_net_sendfunction usbip_net_pack_op_commonfunction usbip_net_send_op_commonfunction usbip_net_recv_op_commonfunction usbip_net_set_reuseaddrfunction usbip_net_set_nodelayfunction usbip_net_set_keepalivefunction usbip_net_set_v6onlyfunction usbip_net_tcp_connect
Annotated Snippet
if (op_common.code != *code) {
dbg("unexpected pdu %#0x for %#0x", op_common.code,
*code);
/* return error status */
*status = ST_ERROR;
goto err;
}
}
*status = op_common.status;
if (op_common.status != ST_OK) {
dbg("request failed at peer: %d", op_common.status);
goto err;
}
*code = op_common.code;
return 0;
err:
return -1;
}
int usbip_net_set_reuseaddr(int sockfd)
{
const int val = 1;
int ret;
ret = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
if (ret < 0)
dbg("setsockopt: SO_REUSEADDR");
return ret;
}
int usbip_net_set_nodelay(int sockfd)
{
const int val = 1;
int ret;
ret = setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
if (ret < 0)
dbg("setsockopt: TCP_NODELAY");
return ret;
}
int usbip_net_set_keepalive(int sockfd)
{
const int val = 1;
int ret;
ret = setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val));
if (ret < 0)
dbg("setsockopt: SO_KEEPALIVE");
return ret;
}
int usbip_net_set_v6only(int sockfd)
{
const int val = 1;
int ret;
ret = setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof(val));
if (ret < 0)
dbg("setsockopt: IPV6_V6ONLY");
return ret;
}
/*
* IPv6 Ready
*/
int usbip_net_tcp_connect(char *hostname, char *service)
{
struct addrinfo hints, *res, *rp;
int sockfd;
int ret;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
/* get all possible addresses */
ret = getaddrinfo(hostname, service, &hints, &res);
if (ret < 0) {
dbg("getaddrinfo: %s service %s: %s", hostname, service,
gai_strerror(ret));
return ret;
Annotation
- Immediate include surface: `sys/socket.h`, `string.h`, `arpa/inet.h`, `netdb.h`, `netinet/tcp.h`, `unistd.h`, `tcpd.h`, `usbip_common.h`.
- Detected declarations: `function usbip_setup_port_number`, `function usbip_net_pack_uint32_t`, `function usbip_net_pack_uint16_t`, `function usbip_net_pack_usb_device`, `function usbip_net_pack_usb_interface`, `function usbip_net_recv`, `function usbip_net_send`, `function usbip_net_pack_op_common`, `function usbip_net_send_op_common`, `function usbip_net_recv_op_common`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.