This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned int index = reciprocal_scale(phash, num_socks); | |
return reuse->socks[index]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ss -tlnpe | grep :45000 | |
LISTEN 0 128 *:45000 *:* users:(("my_server",pid=3020,fd=3),("my_server",pid=3019,fd=3)) ino:3854904087 sk:37d5a0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ss -tlnpe | grep :45000 | |
LISTEN 0 128 *:45000 *:* users:(("my_server",pid=1975,fd=3)) ino:3854935788 sk:37d59c | |
LISTEN 0 128 *:45000 *:* users:(("my_server",pid=1974,fd=3)) ino:3854935786 sk:37d59d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct sock *inet_csk_accept(struct sock *sk) | |
{ | |
struct sock *newsk = NULL; /* client socket */ | |
/* Make sure that this socket is listening, and that it has something pending. */ | |
lock_sock(sk); | |
if (sk->sk_state == TCP_LISTEN) | |
if ("there are completed connections waiting to be accepted") | |
newsk = get_first_connection(sk); | |
release_sock(sk); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server.sin_family = AF_INET; | |
server.sin_port = htons(SERVER_PORT); | |
bcopy(server_ent->h_addr, &server.sin_addr.s_addr, server_ent->h_length); | |
/* Connect to server, and set the socket's destination IP address and port# | |
* based on above parameters. Also, request the kernel to automatically set | |
* the Source IP and port# if the application did not call bind() prior to connect(). | |
*/ | |
connect(fd, (struct sockaddr *)&server, sizeof server); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
srv_addr.sin_family = AF_INET; | |
srv_addr.sin_addr.s_addr = INADDR_ANY; | |
srv_addr.sin_port = htons(SERVER_PORT); | |
bind(fd, &srv_addr, sizeof srv_addr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const struct linger opt = { .l_onoff = 1, .l_linger = 0 }; | |
setsockopt(fd, SOL_SOCKET, SO_LINGER, &opt, sizeof opt); | |
close(fd); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Create a socket: | |
server_fd = socket(...); | |
2. Bind to a well known IP address and port#: | |
ret = bind(server_fd, ...); | |
3. Mark the socket as passive by changing it's state to LISTEN: | |
ret = listen(server_fd, ...); | |
4. Wait for a client to connect, and get a reference file descriptor: | |
client_fd = accept(server_fd, ...); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
entry: | __x64_sys_sendto() { | |
entry: | __sys_sendto() { | |
entry: | sockfd_lookup_light() { | |
exit: 0.722 us | } | |
entry: | sock_sendmsg() { | |
entry: | security_socket_sendmsg() { | |
entry: | apparmor_socket_sendmsg() { | |
exit: 0.763 us | } | |
exit: 1.069 us | } | |
entry: | inet_sendmsg() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<interface type='network'> | |
<mac address='52:54:00:00:12:53'/> | |
<source network='enp66s0f0_br'/> | |
<target dev='tap01'/> | |
<model type='virtio'/> | |
<driver name='vhost' queues='4'/> | |
<link state='down'/> | |
<teaming type='persistent'/> | |
<alias name='ua-backup0'/> | |
</interface> |