LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-14-2004, 10:29 AM   #1
r350
LQ Newbie
 
Registered: Jan 2004
Location: Valhalla
Distribution: Slackware 9.1
Posts: 5

Rep: Reputation: 0
invalid conversion from `int*' to `socklen_t*'


This code compiles fine in gcc but when I'm using g++ whith some added c++ syntax it wont compile.

Code:
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "main.h"
using namespace std;


#define MYPORT 3490	//porten som det andra programet connectar till
#define BACKLOG 10

int main(){
	
	//själva initieringen av severn
	int sockfd, new_fd;
	sockaddr_in my_addr;		//min address
	sockaddr_in their_addr;	//deras address
   int sin_size;
	
	sockfd = socket(AF_INET, SOCK_STREAM, 0);
	
	
	my_addr.sin_family = AF_INET;
	my_addr.sin_port = htons(MYPORT);
	my_addr.sin_addr.s_addr = INADDR_ANY;
	memset(&(my_addr.sin_zero), '\0', 8);
	

	

	bind(sockfd, (sockaddr *)&my_addr, sizeof(struct sockaddr));
	//slutet 
	
	//kopplingen
	listen(sockfd, BACKLOG);
	sin_size = sizeof(sockaddr_in);
	
	
	new_fd = accept(sockfd, (sockaddr *)&their_addr, &sin_size);
	shutdown(sockfd, 2); //behöver inte lyssna för ny längre
	send(new_fd, "BANAN\n", 6, 0); 
	
	
	shutdown(new_fd, 2); //stänger av uppkopplingen
	 
	
	return 0;
}
Code is taken from beej's socket tutorial.
 
Old 02-14-2004, 10:49 AM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
What line does the error occur on?
 
Old 02-14-2004, 10:50 AM   #3
r350
LQ Newbie
 
Registered: Jan 2004
Location: Valhalla
Distribution: Slackware 9.1
Posts: 5

Original Poster
Rep: Reputation: 0
ohh sorry, line 42: new_fd = accept(sockfd, (sockaddr *)&their_addr, &sin_size);
 
Old 02-14-2004, 11:55 AM   #4
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Hm, according to the accept manual page, the third parameter needs to be a socklen_t pointer; so I suppose what you'd need to do is cast the int pointer you're passing in to a socklen_t pointer:

new_fd = accept(sockfd, (sockaddr *)&their_addr, (socklen_t*)&sin_size);

Not sure if that's the best way to do it, but it should work...

Seems that there is an alternate version of the accept() function that does in fact take an int pointer, which may be what the author was using.
 
Old 02-14-2004, 11:58 AM   #5
r350
LQ Newbie
 
Registered: Jan 2004
Location: Valhalla
Distribution: Slackware 9.1
Posts: 5

Original Poster
Rep: Reputation: 0
Thank you very much, it worked like charm.
 
Old 10-02-2011, 05:34 PM   #6
ericsun
LQ Newbie
 
Registered: Oct 2011
Posts: 1

Rep: Reputation: Disabled
Thanks , mine works~~
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C programming - Char to Int Conversion ? indian Programming 4 09-30-2005 08:00 AM
C programming int to char conversion paranoid times Programming 15 03-17-2005 11:06 PM
invalid types int[int] for array subscript scuzzman Programming 2 11-16-2004 09:34 PM
squirremail ...it says invalid user or invalid password. rnj Fedora 9 10-25-2004 09:56 PM
invalid conversion from `char' to `const char* bru Programming 6 05-09-2004 03:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration