Article View: es.comp.os.linux.programacion
Article #10341Segmentation fault (core dumped) al crear Socket
From: el cintura partida
Date: Sat, 09 Mar 2002 14:11
Date: Sat, 09 Mar 2002 14:11
78 lines
3288 bytes
3288 bytes
Hola a todos, tengo problemas a la hora de generar socket en mi
m�quina Linux, he intentado crear socket de entorno TCP y UNIX pero
siempre aparece el mensaje:
Segmentation fault (core dumped)
Los c�digos fuente han sido sacados de libros de texto y/e Internet
pero no conseguido crearlo porque el dichoso Segmentation fault (core
dumped) siempre me aparece.
Haciedo un debug de la memoria con la herramienta Electric Fence
obtengo:
[root@localhost /root]# gcc helper.c crear_socket.c -o crear_socket
-lefence
crear_socket.c: In function `main':
crear_socket.c:27: warning: passing arg 2 of `strncpy' makes pointer
from integer without a cast
[root@localhost /root]# gdb -q crear_socket lpe-sample
(gdb) run lpe_sample
Starting program: /root/crear_socket lpe_sample
Program received signal SIGSEGV, Segmentation fault.
strncpy (s1=0xbffffc36 "", s2=0xfffffffd <Address 0xfffffffd out of
bounds>, n=108) at ../sysdeps/generic/strncpy.c:41
../sysdeps/generic/strncpy.c:41: No such file or directory.
(gdb) quit
El c�digo fuente es:
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/types.h>
#include <stdlib.h>
#include "helper.h"
#include <stdio.h>
int main (int argc, char *argv)
{
int descriptor_socket;
struct sockaddr_un struc_servidor,srv; /* Estructura de socket en el
servidor */
socklen_t tamano_direccion;
if (argc != 2) {
puts("MODO DE EMPLEO: crear_socket <nombre de socket>");
exit (EXIT_FAILURE);
}
/* Crear el Socket */
if ((descriptor_socket = socket (PF_UNIX, SOCK_STREAM,0))< 0)
err_quit("socket"); /* Definida en helper.h e implementada en
helper.c*/
/* Iniciar y establecer la estructura del servidor */
memset(&struc_servidor, 0, sizeof(struc_servidor));
struc_servidor.sun_family = AF_UNIX;
strncpy (struc_servidor.sun_path, argv[1],
sizeof(struc_servidor.sun_path));
/* Ligar socket a una direccion */
if ((bind(descriptor_socket,(struct sockaddr *)&struc_servidor,
SUN_LEN(&struc_servidor)))<0);
/* Aguardar por las conexiones que arriben */
if ((listen(descriptor_socket, 5))<0)
err_quit("listen");
printf("Socket disponible: %s\n", struc_servidor.sun_path);
/* Mantener un lazo infinito, aceptando todas las conexiones */
while (accept (descriptor_socket, (struct sockaddr *)&srv, &
tamano_direccion)>=0)
puts ("La nueva conexi�n ha sido habilitada");
exit (EXIT_SUCCESS);
}
Muchas gracias a culquiera que me lea. Un saludo
Technical Details
Message-ID:
<ffaaf19a.0203090611.f84f90a@posting.google.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: f86c8,6012a616144366d,start X-Google-Attributes: gidf86c8,public X-Google-ArrivalTime: 2002-03-09 06:11:19 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail From: elcinturapartida@yahoo.es (el cintura partida) Newsgroups: es.comp.os.linux.programacion Subject: Segmentation fault (core dumped) al crear Socket Date: 9 Mar 2002 06:11:19 -0800 Organization: http://groups.google.com/ Lines: 78 Message-ID: <ffaaf19a.0203090611.f84f90a@posting.google.com> NNTP-Posting-Host: 213.99.117.234 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1015683079 27710 127.0.0.1 (9 Mar 2002 14:11:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 9 Mar 2002 14:11:19 GMT