// server
#pragma comment(lib, "ws2_32.lib")
#include <WinSock2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
//#include <sys/socket.h>
//#include <netinet/in.h>
//#include <netdb.h>
#define PORT 12345 /*適当な番号 */
int main(int argc, char* argv[])
{
WSADATA wsaData;
char hostname[64];
struct hostent *host;
struct sockaddr_in me;
int s0,s,n;
char buf[512];
WSAStartup(MAKEWORD(2, 2), &wsaData);
gethostname(hostname,64);
host = gethostbyname(hostname);
// bzero((char *)&me,sizeof(me));
me.sin_family = AF_INET;
me.sin_port = htons(PORT);
// me.sin_addr = *(struct in_addr *)host->h_addr;
me.sin_addr.s_addr = INADDR_ANY;
s0 = socket(AF_INET, SOCK_STREAM, 0);
if(bind(s0, (const struct sockaddr *)&me, sizeof(me)) < 0){
fprintf(stderr
,"cannot bind socket\n"); }
listen(s0,1);
s = accept(s0,NULL,NULL);
while (fgets(buf
, 512, stdin
)) { send(s, buf, n, 0);
}
shutdown(s, SD_BOTH);
closesocket(s0);
closesocket(s);
WSACleanup();
return 0;
}
Ly8gc2VydmVyCiNwcmFnbWEgY29tbWVudChsaWIsICJ3czJfMzIubGliIikKI2luY2x1ZGUgPFdpblNvY2syLmg+CgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RyaW5nLmg+CiNpbmNsdWRlIDxzeXMvdHlwZXMuaD4KLy8jaW5jbHVkZSA8c3lzL3NvY2tldC5oPgovLyNpbmNsdWRlIDxuZXRpbmV0L2luLmg+Ci8vI2luY2x1ZGUgPG5ldGRiLmg+CiNkZWZpbmUgUE9SVCAxMjM0NSAvKumBqeW9k+OBqueVquWPtyAqLwoKaW50IG1haW4oaW50IGFyZ2MsIGNoYXIqIGFyZ3ZbXSkKewoJV1NBREFUQQl3c2FEYXRhOwoJY2hhciBob3N0bmFtZVs2NF07CglzdHJ1Y3QgaG9zdGVudCAqaG9zdDsKCXN0cnVjdCBzb2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