mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 12:16:00 +00:00
Fix gethostname calls (bug #4198, with mods)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5600 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
4
acl.c
4
acl.c
@@ -405,7 +405,7 @@ struct ast_netsock *ast_netsock_bind(struct ast_netsock_list *list, struct io_co
|
|||||||
|
|
||||||
int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr)
|
int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr)
|
||||||
{
|
{
|
||||||
char ourhost[256];
|
char ourhost[MAXHOSTNAMELEN]="";
|
||||||
struct ast_hostent ahp;
|
struct ast_hostent ahp;
|
||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
struct in_addr saddr;
|
struct in_addr saddr;
|
||||||
@@ -416,7 +416,7 @@ int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* try to use our hostname */
|
/* try to use our hostname */
|
||||||
if (gethostname(ourhost, sizeof(ourhost))) {
|
if (gethostname(ourhost, sizeof(ourhost)-1)) {
|
||||||
ast_log(LOG_WARNING, "Unable to get hostname\n");
|
ast_log(LOG_WARNING, "Unable to get hostname\n");
|
||||||
} else {
|
} else {
|
||||||
hp = ast_gethostbyname(ourhost, &ahp);
|
hp = ast_gethostbyname(ourhost, &ahp);
|
||||||
|
@@ -1463,7 +1463,7 @@ static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *c
|
|||||||
FILE *p=NULL;
|
FILE *p=NULL;
|
||||||
int pfd;
|
int pfd;
|
||||||
char date[256];
|
char date[256];
|
||||||
char host[256];
|
char host[MAXHOSTNAMELEN] = "";
|
||||||
char who[256];
|
char who[256];
|
||||||
char bound[256];
|
char bound[256];
|
||||||
char fname[256];
|
char fname[256];
|
||||||
@@ -1491,7 +1491,7 @@ static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p) {
|
if (p) {
|
||||||
gethostname(host, sizeof(host));
|
gethostname(host, sizeof(host)-1);
|
||||||
if (strchr(srcemail, '@'))
|
if (strchr(srcemail, '@'))
|
||||||
strncpy(who, srcemail, sizeof(who)-1);
|
strncpy(who, srcemail, sizeof(who)-1);
|
||||||
else {
|
else {
|
||||||
@@ -1618,7 +1618,7 @@ static int sendpage(char *srcemail, char *pager, int msgnum, char *context, char
|
|||||||
FILE *p=NULL;
|
FILE *p=NULL;
|
||||||
int pfd;
|
int pfd;
|
||||||
char date[256];
|
char date[256];
|
||||||
char host[256];
|
char host[MAXHOSTNAMELEN]="";
|
||||||
char who[256];
|
char who[256];
|
||||||
char dur[256];
|
char dur[256];
|
||||||
char tmp[80] = "/tmp/astmail-XXXXXX";
|
char tmp[80] = "/tmp/astmail-XXXXXX";
|
||||||
@@ -1637,7 +1637,7 @@ static int sendpage(char *srcemail, char *pager, int msgnum, char *context, char
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (p) {
|
if (p) {
|
||||||
gethostname(host, sizeof(host));
|
gethostname(host, sizeof(host)-1);
|
||||||
if (strchr(srcemail, '@'))
|
if (strchr(srcemail, '@'))
|
||||||
strncpy(who, srcemail, sizeof(who)-1);
|
strncpy(who, srcemail, sizeof(who)-1);
|
||||||
else {
|
else {
|
||||||
|
10
asterisk.c
10
asterisk.c
@@ -273,12 +273,12 @@ static pthread_t lthread;
|
|||||||
static void *netconsole(void *vconsole)
|
static void *netconsole(void *vconsole)
|
||||||
{
|
{
|
||||||
struct console *con = vconsole;
|
struct console *con = vconsole;
|
||||||
char hostname[256];
|
char hostname[MAXHOSTNAMELEN]="";
|
||||||
char tmp[512];
|
char tmp[512];
|
||||||
int res;
|
int res;
|
||||||
struct pollfd fds[2];
|
struct pollfd fds[2];
|
||||||
|
|
||||||
if (gethostname(hostname, sizeof(hostname)))
|
if (gethostname(hostname, sizeof(hostname)-1))
|
||||||
strncpy(hostname, "<Unknown>", sizeof(hostname)-1);
|
strncpy(hostname, "<Unknown>", sizeof(hostname)-1);
|
||||||
snprintf(tmp, sizeof(tmp), "%s/%d/%s\n", hostname, ast_mainpid, ASTERISK_VERSION);
|
snprintf(tmp, sizeof(tmp), "%s/%d/%s\n", hostname, ast_mainpid, ASTERISK_VERSION);
|
||||||
fdprint(con->fd, tmp);
|
fdprint(con->fd, tmp);
|
||||||
@@ -1026,7 +1026,7 @@ static char *cli_prompt(EditLine *el)
|
|||||||
memset(prompt, 0, sizeof(prompt));
|
memset(prompt, 0, sizeof(prompt));
|
||||||
while (*t != '\0' && *p < sizeof(prompt)) {
|
while (*t != '\0' && *p < sizeof(prompt)) {
|
||||||
if (*t == '%') {
|
if (*t == '%') {
|
||||||
char hostname[256];
|
char hostname[MAXHOSTNAMELEN]="";
|
||||||
int i;
|
int i;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
@@ -1668,7 +1668,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
char filename[80] = "";
|
char filename[80] = "";
|
||||||
char hostname[256];
|
char hostname[MAXHOSTNAMELEN]="";
|
||||||
char tmp[80];
|
char tmp[80];
|
||||||
char * xarg = NULL;
|
char * xarg = NULL;
|
||||||
int x;
|
int x;
|
||||||
@@ -1693,7 +1693,7 @@ int main(int argc, char *argv[])
|
|||||||
option_remote++;
|
option_remote++;
|
||||||
option_nofork++;
|
option_nofork++;
|
||||||
}
|
}
|
||||||
if (gethostname(hostname, sizeof(hostname)))
|
if (gethostname(hostname, sizeof(hostname)-1))
|
||||||
strncpy(hostname, "<Unknown>", sizeof(hostname)-1);
|
strncpy(hostname, "<Unknown>", sizeof(hostname)-1);
|
||||||
ast_mainpid = getpid();
|
ast_mainpid = getpid();
|
||||||
ast_ulaw_init();
|
ast_ulaw_init();
|
||||||
|
@@ -248,7 +248,7 @@ static int restart_monitor(void);
|
|||||||
static int capability = AST_FORMAT_ULAW;
|
static int capability = AST_FORMAT_ULAW;
|
||||||
static int nonCodecCapability = AST_RTP_DTMF;
|
static int nonCodecCapability = AST_RTP_DTMF;
|
||||||
|
|
||||||
static char ourhost[256];
|
static char ourhost[MAXHOSTNAMELEN];
|
||||||
static struct in_addr __ourip;
|
static struct in_addr __ourip;
|
||||||
static int ourport;
|
static int ourport;
|
||||||
|
|
||||||
@@ -4096,7 +4096,7 @@ static int reload_config(void)
|
|||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
int format;
|
int format;
|
||||||
|
|
||||||
if (gethostname(ourhost, sizeof(ourhost))) {
|
if (gethostname(ourhost, sizeof(ourhost)-1)) {
|
||||||
ast_log(LOG_WARNING, "Unable to get hostname, MGCP disabled\n");
|
ast_log(LOG_WARNING, "Unable to get hostname, MGCP disabled\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
4
logger.c
4
logger.c
@@ -75,7 +75,7 @@ static struct msglist {
|
|||||||
struct msglist *next;
|
struct msglist *next;
|
||||||
} *list = NULL, *last = NULL;
|
} *list = NULL, *last = NULL;
|
||||||
|
|
||||||
static char hostname[256];
|
static char hostname[MAXHOSTNAMELEN];
|
||||||
|
|
||||||
enum logtypes {
|
enum logtypes {
|
||||||
LOGTYPE_SYSLOG,
|
LOGTYPE_SYSLOG,
|
||||||
@@ -294,7 +294,7 @@ static void init_logger_chain(void)
|
|||||||
ast_mutex_lock(&loglock);
|
ast_mutex_lock(&loglock);
|
||||||
if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) {
|
if ((s = ast_variable_retrieve(cfg, "general", "appendhostname"))) {
|
||||||
if(ast_true(s)) {
|
if(ast_true(s)) {
|
||||||
if(gethostname(hostname, sizeof(hostname))) {
|
if(gethostname(hostname, sizeof(hostname)-1)) {
|
||||||
strncpy(hostname, "unknown", sizeof(hostname)-1);
|
strncpy(hostname, "unknown", sizeof(hostname)-1);
|
||||||
ast_log(LOG_WARNING, "What box has no hostname???\n");
|
ast_log(LOG_WARNING, "What box has no hostname???\n");
|
||||||
}
|
}
|
||||||
|
@@ -4453,7 +4453,7 @@ static int set_config(char *config_file, struct sockaddr_in* sin)
|
|||||||
char *cat;
|
char *cat;
|
||||||
int format;
|
int format;
|
||||||
int x;
|
int x;
|
||||||
char hn[256];
|
char hn[MAXHOSTNAMELEN]="";
|
||||||
struct ast_hostent he;
|
struct ast_hostent he;
|
||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
struct sockaddr_in sin2;
|
struct sockaddr_in sin2;
|
||||||
@@ -4470,7 +4470,7 @@ static int set_config(char *config_file, struct sockaddr_in* sin)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ipaddr[0] = '\0';
|
ipaddr[0] = '\0';
|
||||||
if (!gethostname(hn, sizeof(hn))) {
|
if (!gethostname(hn, sizeof(hn)-1)) {
|
||||||
hp = ast_gethostbyname(hn, &he);
|
hp = ast_gethostbyname(hn, &he);
|
||||||
if (hp) {
|
if (hp) {
|
||||||
memcpy(&sin2.sin_addr, hp->h_addr, sizeof(sin2.sin_addr));
|
memcpy(&sin2.sin_addr, hp->h_addr, sizeof(sin2.sin_addr));
|
||||||
|
Reference in New Issue
Block a user