Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Help Debugging


ghost's Avatar
0 0

*#include <stdio.h> #include <stdlib.h> #include <winsock.h>

#define PORT 5842 #define IP "69.55.233.89"

int main(int argc, char *argv[]) { int a,b,c,d,x,sock; char answer[1024]; struct sockaddr_in s;

sock = socket(PF_INET, SOCK_STREAM, 0);

s.sin_family = AF_INET;
s.sin_port = htons(PORT);
s.sin_addr.s_addr = inet_addr(IP);

connect(sock, (struct sockaddr *) &s, sizeof(s));

recv(sock, &a, sizeof(unsigned int), 0);
recv(sock, &b, sizeof(unsigned int), 0);
recv(sock, &c, sizeof(unsigned int), 0);
recv(sock, &d, sizeof(unsigned int), 0);

printf(&quot;a = %d, b = %d, c = %d, d = %d&#92;n&quot;, a, b, c, d);

x = a + b + c + d;

printf(&quot;Sum: %d&#92;n&quot;, x);

send(sock, &x, sizeof(int), 0);

recv(sock, &answer, sizeof(answer), 0);

printf(&quot;s&#92;n&quot;, answer);

system("PAUSE"); return 0; }*

anyone good with socket programming i need help debugging this program, i am getting the following error log:

main.c: In function main&#39;: main.c:24: warning: passing arg 2 of recv' from incompatible pointer type main.c:25: warning: passing arg 2 of recv&#39; from incompatible pointer type main.c:26: warning: passing arg 2 of recv' from incompatible pointer type main.c:27: warning: passing arg 2 of recv&#39; from incompatible pointer type main.c:35: warning: passing arg 2 of send' from incompatible pointer type main.c:37: warning: passing arg 2 of `recv' from incompatible pointer type


Uber0n's Avatar
Member
0 0

int recv(int fd, void *buf, int len, unsigned int flags);

Arguments:

fd -> is the socket descriptor to read from buf -> is the buffer to read the information into len -> is the maximum length of the buffer flags -> set it to 0

Note that the second argument is NOT supposed to be a pointer.

Here's just a simple example using recv()

{
  n=recv(skt, buf, BUFFER_SIZE,0);
  if (n&lt;=0) break;
  buf[n] = &#39;&#92;0&#39;;
  cout &lt;&lt; buf;
}```