Sponsored Content
Top Forums Programming "Symbol referencing errors" On Socket programming Post 302526752 by beyondaymk on Wednesday 1st of June 2011 11:37:33 AM
Old 06-01-2011
"Symbol referencing errors" On Socket programming

Dear all,

I had the "Symbol referencing errors" while compiling a C socket code.
It said "Undefined Symbol: socketpair", but I already copy the two head files (#include "types.h", #include "socket.h") into my current directory.

Could anyone help me with it? Thanks.

By the way, I'm using Solaris, OS version is 5.10.
GCC version is 3.4.6.(is it because the GCC version is old?)
The tut2.c code I was using is from the following link:
A Socket-based IPC Tutorial

I'll copy the source code here:
Code:
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h> 
#include <unistd.h>
#include <stdlib.h>

#define DATA1 "In Xanadu, did Kublai Khan..." 
#define DATA2 "A stately pleasure dome decree..."

/*
 * This program creates a pair of connected sockets, 
 * then forks and communicates over them. While this
 * is very similar to communication with pipes, socketpairs
 * are two-way communications objects. Therefore, I can
 * send messages in both directions.
 */

main()
{
        int sockets[2], child;
        char buf[1024];

        if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) < 0) {
                perror("opening stream socket pair");
                exit(1);
        }

        if ((child = fork()) == -1)
                perror("fork");
        else if (child) {       /* This is the parent. */
                close(sockets[0]);
                if (read(sockets[1], buf, sizeof(buf)) < 0)
                        perror("reading stream message");
                printf("-->%s\n", buf);
                if (write(sockets[1], DATA2, sizeof(DATA2)) < 0)
                        perror("writing stream message");
                close(sockets[1]);
        } else {                /* This is the child. */
                close(sockets[1]);
                if (write(sockets[0], DATA1, sizeof(DATA1)) < 0)
                        perror("writing stream message");
                if (read(sockets[0], buf, sizeof(buf)) < 0) 
                        perror("reading stream message");
                printf("-->%s\n", buf);
                close(sockets[0]);
        }
}

 

10 More Discussions You Might Find Interesting

1. Programming

Compiling Errors -- Symbol referencing

I'm trying to compile a FTP_API program. To do this you must use the libftp.so libary. But that libary has references which are not defined. Has anyone had this problems and how is it corrected?? The command line looks like this:-------------------------------------------- # cc ftpstock.c -lftp... (5 Replies)
Discussion started by: spotanddot
5 Replies

2. UNIX for Dummies Questions & Answers

ld: fatal: Symbol referencing errors

Hello! I have some problems installing a program called “Jail Chroot Project”. http://www.gsyc.inf.uc3m.es/~assman/jail/index.html I have only installed precompiled programs before and I get some kind of error message when im trying to compile this program. I have downloaded and... (2 Replies)
Discussion started by: alfabetman
2 Replies

3. Programming

ld: fatal: Symbol referencing errors. No output written to SNX

Hi all, I am getting the following error when I try to do a build of a product. I dont have the dependencies of the binaries involved in the build and thats the reason I was not able to find which library to add or to proceed to the next step to solve the reference problem. Undefined ... (1 Reply)
Discussion started by: jerryragland
1 Replies

4. Shell Programming and Scripting

ld: fatal: Symbol referencing errors

I am getting below error, any ideas to resolve it. 1:ts_n_tcp_cmp_row /finder3/baseline/95s/ed/src/lib/libfinder_ui_basic.so 1:ui_convert_date /finder3/baseline/95s/ed/src/lib/libfinder_fi_basic.so 1:ld: fatal: Symbol referencing errors. No output written... (1 Reply)
Discussion started by: shafi2all
1 Replies

5. AIX

"too big" and "not enough memory" errors in shell script

Hi, This is odd, however here goes. There are several shell scripts that run in our production environment AIX 595 LPAR m/c, which has sufficient memory 14GB (physical memory) and horsepower 5CPUs. However from time to time we get the following errors in these shell scripts. The time when these... (11 Replies)
Discussion started by: jerardfjay
11 Replies

6. Programming

ld: fatal: Symbol referencing errors

Hi, I'm trying to compile OpenTTD on Solaris 5.10. I do not have root permissions so I have to set the prefix-dir to /home/abcde/usr/local/opt/opentdd-0.6.3 I've used the following command to configure: bash ./configure --prefix-dir=/opt/openttd-0.6.2 --without-makedepend \... (1 Reply)
Discussion started by: rudolph
1 Replies

7. Programming

C++ ld: fatal: Symbol referencing errors.

Hello. I used to compile my code including a third-party library, "libfoo.so". Now, the vendor ships a statically linked library, "libfoo.a", instead. With this library, I run into the following error: CC -mt -xarch=v9 -DCOMPILE_SOL_SPARC -ftrap=%none -xlibmil -xchip=ultra2 -xbuiltin -xO4 \... (0 Replies)
Discussion started by: acheong87
0 Replies

8. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

9. Programming

Symbol referencing errors

Undefined first referenced symbol in file logf /var/tmp//ccwztFsO.o ld: fatal: Symbol referencing errors. No output written to a.out collect2: ld returned 1 exit status float exponC(float mean) { index1++;... (1 Reply)
Discussion started by: willji1234
1 Replies

10. Shell Programming and Scripting

How to allign output data in UNIX that is separated with a pipe "|" symbol ?

Experts , In the given output of the log file, the 2nd field that is separated by "|" pipe is not aligned well due to the uneven data length, I would like it to align the 2nd column with 37 length (that is disturbed in the output) including the pipe . The two pepe "|" would be in a aligned way... (2 Replies)
Discussion started by: rveri
2 Replies
sendfile(3EXT)						    Extended Library Functions						    sendfile(3EXT)

NAME
sendfile - send files over sockets or copy files to files SYNOPSIS
cc [ flag... ] file... -lsendfile [ library... ] #include <sys/sendfile.h> ssize_t sendfile(int out_fd, int in_fd, off_t *off, size_t len); DESCRIPTION
The sendfile() function copies data from in_fd to out_fd starting at offset off and of length len bytes. The in_fd argument should be a file descriptor to a regular file opened for reading. See open(2). The out_fd argument should be a file descriptor to a regular file opened for writing or to a connected AF_INET or AF_INET6 socket of SOCK_STREAM type. See socket(3SOCKET). The off argument is a pointer to a variable holding the input file pointer position from which the data will be read. After sendfile() has completed, the variable will be set to the offset of the byte following the last byte that was read. The sendfile() function does not modify the current file pointer of in_fd, but does modify the file pointer for out_fd if it is a regular file. The sendfile() function can also be used to send buffers by pointing in_fd to SFV_FD_SELF. RETURN VALUES
Upon successful completion, sendfile() returns the total number of bytes written to out_fd and also updates the offset to point to the byte that follows the last byte read. Otherwise, it returns -1, and errno is set to indicate an error. ERRORS
The sendfile() function will fail if: EAFNOSUPPORT The implementation does not support the specified address family for socket. EAGAIN Mandatory file or record locking is set on either the file descriptor or output file descriptor if it points at regular files. O_NDELAY or O_NONBLOCK is set, and there is a blocking record lock. An attempt has been made to write to a stream that cannot accept data with the O_NDELAY or the O_NONBLOCK flag set. EBADF The out_fd or in_fd argument is either not a valid file descriptor, out_fd is not opened for writing. or in_fd is not opened for reading. EINVAL The offset cannot be represented by the off_t structure, or the length is negative when cast to ssize_t. EIO An I/O error occurred while accessing the file system. ENOTCONN The socket is not connected. EOPNOTSUPP The socket type is not supported. EPIPE The out_fd argument is no longer connected to the peer endpoint. USAGE
The sendfile() function has a transitional interface for 64-bit file offsets. See lf64(5). EXAMPLES
Example 1: Sending a Buffer Over a Socket The following example demonstrates how to send the buffer buf over a socket. At the end, it prints the number of bytes transferred over the socket from the buffer. It assumes that addr will be filled up appropriately, depending upon where to send the buffer. int tfd; off_t baddr; struct sockaddr_in sin; char buf[64 * 1024]; in_addr_t addr; tfd = socket(AF_INET, SOCK_STREAM, 0); if (tfd == -1) { perror("socket"); exit(1); } sin.sin_family = AF_INET; sin.sin_addr = addr; /* Fill in the appropriate address. */ sin.sin_port = htons(2345); if (connect(tfd, (struct sockaddr *)&sin, sizeof(sin))<0) { perror("connect"); exit(1); } baddr = (off_t)buf; len = sendfile(tfd, SFV_FD_SELF, &baddr, len); if (len == -1) { perror("sendfile"); exit(1); } printf("Transfered %d bytes from buffer to socket", len); Example 2: Transferring Files to Sockets The following program demonstrates a transfer of files to sockets: int ffd, tfd; off_t off; struct sockaddr_in sin; in_addr_t addr; int len; struct stat stat_buf; ffd = open("file", O_RDONLY); if (ffd == -1) { perror("open"); exit(1); } tfd = socket(AF_INET, SOCK_STREAM, 0); if (tfd == -1) { perror("socket"); exit(1); } sin.sin_family = AF_INET; sin.sin_addr = addr; /* Fill in the appropriate address. */ sin.sin_port = htons(2345); if (connect(tfd, (struct sockaddr *) &sin, sizeof(sin)) <0) { perror("connect"); exit(1); } if (fstat(ffd, &stat_buf) == -1) { perror("fstat"); exit(1); } len = sendfile(tfd, ffd, &off, stat_buf.st_size); if (len == -1) { perror("sendfile"); exit(1); } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
open(2), libsendfile(3LIB), sendfilev(3EXT), socket(3SOCKET), attributes(5), lf64(5) SunOS 5.10 19 Apr 2004 sendfile(3EXT)
All times are GMT -4. The time now is 07:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy