Skip to content

Instantly share code, notes, and snippets.

@cute
Forked from daurnimator/main.c
Created Nov 5, 2019
Embed
What would you like to do?
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
int main(int argc, char **argv) {
int s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s < 0)
{
perror("socket");
return 1;
}
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(80);
addr.sin_len = sizeof(addr);
inet_aton("127.0.0.1", &addr.sin_addr);
sa_endpoints_t endpoints;
endpoints.sae_srcif = 0;
endpoints.sae_srcaddr = NULL;
endpoints.sae_srcaddrlen = 0;
endpoints.sae_dstaddr = (struct sockaddr *)&addr;
endpoints.sae_dstaddrlen = sizeof(addr);
int rc = connectx(s, &endpoints, SAE_ASSOCID_ANY, CONNECT_RESUME_ON_READ_WRITE | CONNECT_DATA_IDEMPOTENT, NULL, 0, NULL, NULL);
if (rc < 0)
{
perror("connectx");
return 1;
}
char buf[1024];
rc = write(s, buf, 1024);
if (rc < 0)
{
perror("write");
return 1;
}
close(s);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment