Skip to content

Instantly share code, notes, and snippets.

@daurnimator
Created September 30, 2015 01:01
Show Gist options
  • Save daurnimator/3f2cfef6f4101e432313 to your computer and use it in GitHub Desktop.
Save daurnimator/3f2cfef6f4101e432313 to your computer and use it in GitHub Desktop.
#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