Monday, March 15, 2010

Error pada Socket Programming

Saat meng-compile file echo_cli.c ada pesan kesalahan sbb :

[msmunir@kasihw pemrograman jaringan]$ gcc -o echo_cli echo_cli.c
echo_cli.c: In function ‘main’:
echo_cli.c:35: warning: incompatible implicit declaration of built-in function ‘exit’
echo_cli.c:39: warning: incompatible implicit declaration of built-in function ‘bzero’
echo_cli.c:44: warning: incompatible implicit declaration of built-in function ‘exit’
echo_cli.c:46: warning: incompatible implicit declaration of built-in function ‘bcopy’
echo_cli.c:50: warning: incompatible implicit declaration of built-in function ‘exit’
[msmunir@kasihw pemrograman jaringan]$

Dari hasil googling (http://gcc.gnu.org/ml/gcc/2006-03/msg00785.html), didapat informasi bahwa ada masalah dengan source code :
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#define SER_PORT 49494

Tambahkan
#include <stdlib.h>

Sehingga menjadi :
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#define SER_PORT 49494

Saat di-compile ulang, pesan kesalahan menjadi :
[msmunir@kasihw pemrograman jaringan]$ gcc -o echo_cli echo_cli.c
echo_cli.c: In function ‘main’:
echo_cli.c:40: warning: incompatible implicit declaration of built-in function ‘bzero’
echo_cli.c:47: warning: incompatible implicit declaration of built-in function ‘bcopy’
[msmunir@kasihw pemrograman jaringan]$

Dari hasil googling untung masalah 'bzero' didapat informasi (http://www.linuxquestions.org/questions/linux-software-2/warning-incompatible-implicit-declaration-of-built-in-function-bzero-635670/) bahwa perlu ditambah include string.h. Sehingga source code menjadi :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#define SER_PORT 49494

Cek port yang digunakan server :
[msmunir@svec pemrograman jaringan]$ netstat -nlptu | grep echo_ser
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:49494 0.0.0.0:* LISTEN 7047/echo_ser
[msmunir@svec pemrograman jaringan]$


Cek port yang digunakan client :
-bash-4.0# yum install tcpdump
-bash-4.0# tcpdump -nte



No comments:

Post a Comment