Hi I have nominatim installed on a ubuntu VM which I use for reverse geo-lookup. All is going well, but nominatim doesn't return the correct object when I do a reverse lookup for a highway entrance (motorway_link):
I found a github issues thread from 2 years ago providing solutions. One of the solutions being changing the address rank for motorway_links from 27 to 26 and the other one being altering the style import file. None of these seem to work for me. Has anyone had any expierence with this? I'm using the latest version of nominatim.
This is the highway section of my Nominatim/settings/import-full.style file:
{
"keys" : ["highway"],
"values" : {
"no" : "skip",
"turning_circle" : "skip",
"mini_roundabout" : "skip",
"noexit" : "skip",
"crossing" : "skip",
"give_way" : "skip",
"stop" : "skip",
"street_lamp" : "main,with_name",
"traffic_signals" : "main,with_name",
"service" : "main,with_name",
"cycleway" : "main,with_name",
"path" : "main,with_name",
"footway" : "main,with_name",
"steps" : "main,with_name",
"bridleway" : "main,with_name",
"track" : "main,with_name",
"byway": "main,with_name",
"motorway_link" : "main",
"trunk_link" : "main",
"primary_link" : "main",
"secondary_link" : "main",
"tertiary_link" : "main",
"" : "main"
}
Content of the highway section of nominatim/settings/import-address.style:
{
"keys" : ["highway"],
"values" : {
"motorway" : "main",
"trunk" : "main",
"primary" : "main",
"secondary" : "main",
"tertiary" : "main",
"unclassified" : "main",
"residential" : "main",
"living_street" : "main",
"pedestrian" : "main",
"road" : "main",
"service" : "main,with_name",
"cycleway" : "main,with_name",
"path" : "main,with_name",
"footway" : "main,with_name",
"steps" : "main,with_name",
"bridleway" : "main,with_name",
"track" : "main,with_name",
"byway": "main,with_name",
"motorway_link" : "main",
"trunk_link" : "main,with_name",
"primary_link" : "main,with_name",
"secondary_link" : "main,with_name",
"tertiary_link" : "main,with_name"
}
highway section of nominatim/settings/address-levels.json:
"highway" : {
"" : 30,
"service" : 27,
"cycleway" : 27,
"path" : 27,
"footway" : 27,
"steps" : 27,
"bridleway" : 27,
"motorway_link" : 26,
"primary_link" : 27,
"trunk_link" : 27,
"secondary_link" : 27,
"tertiary_link" : 27,
"residential" : 26,
"track" : 26,
"unclassified" : 26,
"tertiary" : 26,
"secondary" : 26,
"primary" : 26,
"living_street" : 26,
"trunk" : 26,
"motorway" : 26,
"pedestrian" : 26,
"road" : 26,
"construction" : 26
},
So I have solved. If you look in the nominatim/settings/env.defaults file, you'll see the following lines of code:
# Configuration file for OSM data import.
# This may either be the name of one of an internal style or point
# to a file with a custom style.
# Internal styles are: admin, street, address, full, extratags
NOMINATIM_IMPORT_STYLE=extratags
This means that you'll need to alter the extratags-import.style file to allow unnamed motorway_links aswell.
So change the highway section in nominatim/settings/extratags-import.style from this:
{
"keys" : ["highway"],
"values" : {
"no" : "skip",
"turning_circle" : "skip",
"mini_roundabout" : "skip",
"noexit" : "skip",
"crossing" : "skip",
"give_way" : "skip",
"stop" : "skip",
"street_lamp" : "main,with_name",
"traffic_signals" : "main,with_name",
"service" : "main,with_name",
"cycleway" : "main,with_name",
"path" : "main,with_name",
"footway" : "main,with_name",
"steps" : "main,with_name",
"bridleway" : "main,with_name",
"track" : "main,with_name",
"byway": "main,with_name",
"motorway_link" : "main,with_name",
"trunk_link" : "main,with_name",
"primary_link" : "main,with_name",
"secondary_link" : "main,with_name",
"tertiary_link" : "main,with_name",
"" : "main"
}
to this:
{
"keys" : ["highway"],
"values" : {
"no" : "skip",
"turning_circle" : "skip",
"mini_roundabout" : "skip",
"noexit" : "skip",
"crossing" : "skip",
"give_way" : "skip",
"stop" : "skip",
"street_lamp" : "main,with_name",
"traffic_signals" : "main,with_name",
"service" : "main,with_name",
"cycleway" : "main,with_name",
"path" : "main,with_name",
"footway" : "main,with_name",
"steps" : "main,with_name",
"bridleway" : "main,with_name",
"track" : "main,with_name",
"byway": "main,with_name",
"motorway_link" : "main",
"trunk_link" : "main",
"primary_link" : "main",
"secondary_link" : "main",
"tertiary_link" : "main",
"" : "main"
}
Altering these lines of code tells nominatim to not skipp unnamed motorway_links during import.
So if you find yourself having the same issue. Do the following things:
Go to the highway section in nominatim/settings/adress-levels.json and change the address rank of 'motorway_link' from 27 to 26
In the highway section of the import style files (import-full.style, import-address.style, extratags-import.style) change "motorway_link" : "main,with_name" to "motorway_link" : "main"
Reimport the data
/*
typedef struct _HRFS_VOLUME_CONTROL_BLOCK
{
FSRTL_ADVANCED_FCB_HEADER VolumeFileHeader;
ULONG nodeType;
FAST_MUTEX AdvancedFcbHeaderMutex;
....
};
*/
DumpFileObject(*(pVolDev->fileObject));
Vcb = (HRFS_VOLUME_CONTROL_BLOCK_PTR)ExAllocatePool(PagedPool, sizeof(HRFS_VOLUME_CONTROL_BLOCK));
pVolDev->fileObject->SectionObjectPointer = \
(PSECTION_OBJECT_POINTERS)ExAllocatePool(PagedPool, sizeof(SECTION_OBJECT_POINTERS));;
pVolDev->fileObject->WriteAccess = TRUE;
pVolDev->fileObject->ReadAccess = TRUE;
pVolDev->fileObject->DeleteAccess = TRUE;
pVolDev->fileObject->FsContext = &HrfsData.gVolume;
pVolDev->fileObject->Vpb = Vpb;
CC_FILE_SIZES fileSize;
fileSize.AllocationSize.QuadPart = fileSize.FileSize.QuadPart = sizeof(PACKED_BOOT_SECTOR);
fileSize.ValidDataLength.QuadPart = 0xFFFFFFFFFFFFFFFF;
CcInitializeCacheMap(pVolDev->fileObject,
&fileSize,
TRUE,
&HrfsData.CacheManagerNoOpCallbacks,
Vcb);
In this Code segment a crash occured when I call the CcInitializeCacheMap function.
The FILE_OBJECT and the dump infomation is as below :
fileObject.Size : d8
fileObject.DeviceObject : c2221670
fileObject.Vpb : c39302e0
fileObject.FsContext : 32166f0
fileObject.FsContext2 : 0
fileObject.SectionObjectPointer : 0
fileObject.PrivateCacheMap : 0
fileObject.FinalStatus : 0
fileObject.RelatedFileObject : 0
fileObject.LockOperation : 0
fileObject.DeletePending : 0
fileObject.ReadAccess : 1
fileObject.WriteAccess : 1
fileObject.DeleteAccess : 1
fileObject.SharedRead : 0
fileObject.SharedWrite : 0
fileObject.SharedDelete : 0
fileObject.Flags : 40100
fileObject.FileName : 247bb70
fileObject.CurrentByteOffset : 0
fileObject.Waiters : 0
fileObject.Busy : 0
fileObject.LastLock : 0
fileObject.FileObjectExtension : 0
The stack text is as below:
fffff880`0247bac0 fffff880`03241c78 : fffff880`00000000 00000000`00000000 00000000`00000001 fffff880`032166c8 : nt!CcInitializeCacheMap+0xd3
fffff880`0247bba0 fffff880`0323e095 : fffffa80`c303b010 fffffa80`c2222040 fffffa80`c39302e0 fffffa80`c3d56a40 : fastfatDemo!FatMountVolume+0xaf8 [G:\BaiduNetdiskDownload\fastfat_V1G13\fastfat_File_System_Driver\FsCtrl.c # 1460]
fffff880`0247c2f0 fffff880`0323ecb7 : fffffa80`c303b010 fffffa80`c259bb40 00000000`00000065 00000000`00000003 : fastfatDemo!FatCommonFileSystemControl+0xe5 [G:\BaiduNetdiskDownload\fastfat_V1G13\fastfat_File_System_Driver\FsCtrl.c # 1053]
fffff880`0247c340 fffff880`0113d4bc : fffffa80`c3d56a40 fffffa80`c259bb40 00000000`00000000 00000000`00000000 : fastfatDemo!FatFsdFileSystemControl+0x127 [G:\BaiduNetdiskDownload\fastfat_V1G13\fastfat_File_System_Driver\FsCtrl.c # 969]
fffff880`0247c3a0 fffff880`01138971 : fffffa80`c3d56450 00000000`00000000 fffffa80`c3024200 fffffa80`c3129cb0 : fltmgr!FltpFsControlMountVolume+0x28c
fffff880`0247c470 fffff800`04334e6b : fffffa80`c3d56450 00000000`00000000 fffffa80`c3d56450 fffffa80`c259bb40 : fltmgr!FltpFsControl+0x101
fffff880`0247c4d0 fffff800`040789e7 : fffff880`0247c7c0 fffff880`0247c701 fffffa80`c2221600 00000000`00000000 : nt!IopMountVolume+0x28f
fffff880`0247c590 fffff800`044fac6d : 00000000`00000025 00000000`00000000 fffff880`0247c7c0 fffff880`0247c768 : nt!IopCheckVpbMounted+0x1b7
fffff880`0247c600 fffff800`044229a4 : fffffa80`c2221670 00000000`00000000 fffffa80`c31dbb10 fffff8a0`00000001 : nt!IopParseDevice+0xb4d
fffff880`0247c760 fffff800`042fd756 : 00000000`00000000 fffff880`0247c8e0 00000000`00000040 fffffa80`c15c07b0 : nt!ObpLookupObjectName+0x784
fffff880`0247c860 fffff800`044c9d88 : fffffa80`c3d20cb0 00000000`00000000 00000000`00000401 fffff800`043fdef6 : nt!ObOpenObjectByName+0x306
fffff880`0247c930 fffff800`0435d7f4 : fffffa80`c629f870 fffff8a0`80100080 00000000`0029f4f8 00000000`0029f448 : nt!IopCreateFile+0xa08
fffff880`0247c9e0 fffff800`040b4bd3 : fffffa80`c3539b00 00000000`00000001 fffffa80`c629f870 fffff800`042fe1e4 : nt!NtCreateFile+0x78
fffff880`0247ca70 00000000`77629dda : 000007fe`fd3760d6 00000000`00000000 00000000`80000000 00000000`00000000 : nt!KiSystemServiceCopyEnd+0x13
00000000`0029f428 000007fe`fd3760d6 : 00000000`00000000 00000000`80000000 00000000`00000000 00000000`000c0000 : ntdll!ZwCreateFile+0xa
00000000`0029f430 00000000`773b0add : 00000000`0034bec0 00000000`80000000 00000000`00000003 00000000`0029f892 : KERNELBASE!CreateFileW+0x2cd
00000000`0029f590 000007fe`f1971c1e : 00000000`00000000 00000000`00000000 00000000`01d14280 00000000`0029f830 : kernel32!CreateFileWImplementation+0x7d
00000000`0029f5f0 00000000`00000000 : 00000000`00000000 00000000`01d14280 00000000`0029f830 00000000`00000003 : FVEAPI+0x1c1e
I traced the address to nt!CcInitializeCacheMap+0xd3
and found there is a compaire instruction .
So what courced the crash to CcInitializeCacheMap by my program ?
This code should not set to PagedPool Type .
//ErrorCode:
Vcb = (HRFS_VOLUME_CONTROL_BLOCK_PTR)ExAllocatePool(PagedPool, sizeof(HRFS_VOLUME_CONTROL_BLOCK));
pVolDev->fileObject->SectionObjectPointer = \
(PSECTION_OBJECT_POINTERS)ExAllocatePool(PagedPool, sizeof(SECTION_OBJECT_POINTERS));;
I have a script, it work perfectly and everything is show on my power shell screen "Console". But I try to figure Out how to export in CSV
Script:
foreach($vds in Get-VDSwitch)
{
$vds.ExtensionData.Runtime.HostMemberRuntime | %{
$.HealthCheckResult | where{$ -is [VMware.Vim.VMwareDVSVlanHealthCheckResult]} |
Select #{N='vdSwitch';E={$vds.Name}},
UplinkPortKey,
#{N='TrunkedVLAN';E={
($.TrunkedVLAN | %{
if($.Start -eq $.End){
"{0}" -f $.Start
}
else{
"{0}-{1}" -f $.Start,$.End
}
}) -join ','
}}
}
}
The Output on screen look like this;
VsanEnabled : False
VsanDiskClaimMode : Manual
HATotalSlots : 3099
HAUsedSlots : 22
HAAvailableSlots : 1527
HASlotCpuMHz : 32
HASlotMemoryMb : 328
HASlotMemoryGB : 0.3203125
HASlotNumVCpus : 1
ParentId : Folder-group-h28
ParentFolder : host
HAEnabled : True
HAAdmissionControlEnabled : True
HAFailoverLevel : 1
HARestartPriority : Medium
HAIsolationResponse : DoNothing
VMSwapfilePolicy : WithVM
DrsEnabled : True
DrsMode : FullyAutomated
DrsAutomationLevel : FullyAutomated
EVCMode : intel-nehalem
Name : mac01dmzp01
CustomFields : {}
ExtensionData : VMware.Vim.ClusterComputeResource
Id : ClusterComputeResource-domain-c12033
Uid : /VIServer=cn\t175726#mac01vcp02.cn.ca:443/Cluster=ClusterComputeResource-domain-c12033/
vdSwitch : vds-toronto-mac01-2-ports-10Gbe
UplinkPortKey : 78
TrunkedVLAN : 11-17,396,500
vdSwitch : vds-toronto-mac01-2-ports-10Gbe
UplinkPortKey : 79
TrunkedVLAN : 11-17,396,500
vdSwitch : vds-toronto-mac01-2-ports-10Gbe
UplinkPortKey : 82
TrunkedVLAN : 11-17,396,500
vdSwitch : vds-toronto-mac01-2-ports-10Gbe
UplinkPortKey : 83
TrunkedVLAN : 11-17,396,500
vdSwitch : vds-toronto-mac01-2-ports-10Gbe
UplinkPortKey : 358
TrunkedVLAN : 11-17,396,500
vdSwitch : vds-toronto-mac01-2-ports-10Gbe
UplinkPortKey : 359
TrunkedVLAN : 11-17,396,500
a lot more ......
I found the way to do it, is with a function.
#####################################################
# vSphere 6.5
# Get ESX HealthCheck Network Config from VDS
#
# by Gerald Begin (Nov.20 2018)
#################################
##### Set Script Location
Set-Location T:\___Main-Script___\_VDS-vLANs_
##### Add VMWare Module.
Get-Module -Name VMware* -ListAvailable | Import-Module
##### Output Path
$Desti = 'T:\___Main-Script___\_VDS-vLANs_\Output'
Import-Module -Name "T:\__Script_Functions__\Connect2All.ps1" -Force:$true # Function to Connect to ALL vCenters
$Clster = "mac01dmzp01"
#### --------------------------------------
function GetInfo {
###################################################
foreach($vds in Get-VDSwitch)
{
$vds.ExtensionData.Runtime.HostMemberRuntime | %{
$_.HealthCheckResult | where{$_ -is [VMware.Vim.VMwareDVSVlanHealthCheckResult]} |
Select #{N='vdSwitch';E={$vds.Name}},
UplinkPortKey,
#{N='TrunkedVLAN';E={
($_.TrunkedVLAN | %{
if($_.Start -eq $_.End){
"{0}" -f $_.Start
}
else{
"{0}-{1}" -f $_.Start,$_.End
}
}) -join ','
}}
}
}
}
Get-Cluster -Name $Clster | GetInfo | Export-Csv -Path $Desti\Results.csv -NoTypeInformation
Disconnect-VIServer * -Confirm:$false
I want to extract the addressId for a given housenumber in a response with a long array. The array response looks like this (snippet):
: : "footprint":null,
: : "type":null,
: : "addressId":"0011442239",
: : "streetName":"solitudestr.",
: : "streetNrFirstSuffix":null,
: : "streetNrFirst":null,
: : "streetNrLastSuffix":null,
: : "streetNrLast":null,
: : "houseNumber":"25",
: : "houseName":null,
: : "city":"stuttgart",
: : "postcode":"70499",
: : "stateOrProvince":null,
: : "countryName":null,
: : "poBoxNr":null,
: : "poBoxType":null,
: : "attention":null,
: : "geographicAreas":
: : [
: : ],
: : "firstName":null,
: : "lastName":null,
: : "title":null,
: : "region":"BW",
: : "additionalInfo":null,
: : "properties":
: : [
: : ],
: : "extAddressId":null,
: : "entrance":null,
: : "district":null,
: : "addressLine1":null,
: : "addressLine2":null,
: : "addressLine3":null,
: : "addressLine4":null,
: : "companyName":null,
: : "contactName":null,
: : "houseNrExt":null,
: : "derbyStack":false
: },
: {
: : "footprint":null,
: : "type":null,
: : "addressId":"0011442246",
: : "streetName":"solitudestr.",
: : "streetNrFirstSuffix":null,
: : "streetNrFirst":null,
: : "streetNrLastSuffix":null,
: : "streetNrLast":null,
: : "houseNumber":"26",
: : "houseName":null,
: : "city":"stuttgart",
: : "postcode":"70499",
: : "stateOrProvince":null,
: : "countryName":null,
: : "poBoxNr":null,
: : "poBoxType":null,
: : "attention":null,
: : "geographicAreas":
: : [
: : ],
: : "firstName":null,
: : "lastName":null,
: : "title":null,
: : "region":"BW",
: : "additionalInfo":null,
: : "properties":
: : [
: : ],
: : "extAddressId":null,
: : "entrance":null,
: : "district":null,
: : "addressLine1":null,
: : "addressLine2":null,
: : "addressLine3":null,
: : "addressLine4":null,
: : "companyName":null,
: : "contactName":null,
: : "houseNrExt":null,
: : "derbyStack":false
: },
i only show 2 housenumbers in this response as an example but the original response is bigger.
Q: How can i match the adressId for a specific houseNumber (i have these houseNumbers in my CSV dataset) ? I Could do a regex which extracts all addressId's but then i'd have to use the correct matching no. in Jmeter. However, i cannot assume that the ordening of these will remain same in the different environments we test the script against.
I would recommend reconsidering using regular expressions to deal with JSON data.
Starting from JMeter 3.0 you have a JSON Path PostProcessor. Using it you can execute arbitrary JSONPath queries so extracting the addressID for the given houseNumber would be as simple as:
`$..[?(#.houseNumber == '25')].addressId`
Demo:
You can use a JMeter Variable instead of the hard-coded 25 value like:
$..[?(#.houseNumber == '${houseNumber}')].addressId
If for some reason you have to use JMeter < 3.0 you still can have JSON Path postprocessing capabilities using JSON Path Extractor via JMeter Plugins
See Advanced Usage of the JSON Path Extractor in JMeter article, in particular Conditional Select chapter for more information.
You may use a regex that will capture the digits after addressId and before a specific houseNumber if you use an unrolled tempered greedy token (for better efficiency) in between them to make sure the regex engine does not overflow to another record.
"addressId":"(\d+)"(?:[^\n"]*(?:\n(?!: +: +\[)[^\n"]*|"(?!houseNumber")[^\n"]*)*"houseNumber":"25"|$)
See the regex demo (replace 25 with the necessary house number)
Details:
"addressId":" - literal string
(\d+) - Group 1 ($1$ template value) capturing 1+ digits
" - a quote
(?:[^\n"]*(?:\n(?!: +: +\[)[^\n"]*|"(?!houseNumber")[^\n"]*)*"houseNumber":"25"|$) - a non-capturing group with 2 alternatives, one being $ (end of string) or:
[^\n"]* - zero or more chars other than newline and "
(?: - then come 2 alternatives:
\n(?!: +: +\[)[^\n"]* - a newline not followed with : : [ like string and followed with 0+chars other than a newline and "
| - or
"(?!houseNumber")[^\n"]* - a " not followed with houseNumber and followed with 0+chars other than a newline and "
)* - than may repeat 0 or more times
"houseNumber":"25" - hourse number literal string.
not sure why i got this segmentation fault..
normal usage is okay, like when i search for country details . but when i use list, not sure if its overloaded or what, it just give a segmentation fault
Please enter country > Malaysia
Malaysia's Capital : Kuala Lumpur
Malaysia's Currency : Malaysian Ringgit
Malaysia's Currency Code : MYR
Malaysia's Region : Southeast Asia
Malaysia's Population : 22229040.00
Please enter country > russia
Russia's Capital : Moscow
Russia's Currency : Russian Ruble
Russia's Currency Code : RUB
Russia's Region : Asia
Russia's Population : 145470197.00
Please enter country > singapore
Singapore's Capital : Singapore
Singapore's Currency : Singapore Dollar
Singapore's Currency Code : SGD
Singapore's Region : Southeast Asia
Singapore's Population : 4300419.00
Please enter country > list
Country : Andorra
Country : United Arab Emirates
Country : Afghanistan
Country : Antigua and Barbuda
Country : Anguilla
Country : Albania
Country : Armenia
Country : Netherlands Antilles
Country : Angola
Country : Antarctica
Country : Argentina
Country : American Samoa
Country : Austria
Country : Australia
Country : Aruba
Country : Azerbaijan
Country : Bosnia and Herzegovina
Country : Barbados
Country : Bangladesh
Country : Belgium
Country : Burkina Faso
Country : Bulgaria
Country : Bahrain
Country : Burundi
Country : Benin
Country : Bermuda
Country : Brunei Darussalam
Country : Bolivia
Country : Brazil
Country : The Bahamas
Country : Bhutan
Country : Bouvet Island
Country : Botswana
Country : Belarus
Country : Belize
Country : Canada
Country : Cocos (Keeling) Islands
Country : Congo
Country : Central African Republic
Country : Congo
Country : Switzerland
Country : Cote d'Ivoire
Country : Cook Islands
Country : Chile
Country : Cameroon
Country : China
Country : Colombia
Country : Costa Rica
Country : Cuba
Country : Cape Verde
Country : Christmas Island
Country : Cyprus
Country : Czech Republic
Country : Germany
Country : Djibouti
Country : Denmark
Country : Dominica
Country : Dominican Republic
Country : Algeria
Country : Ecuador
Country : Estonia
Country : Egypt
Country : Western Sahara
Country : Eritrea
Country : Spain
Country : Ethiopia
Country : Finland
Country : Fiji
Country : Falkland Islands (Islas Malvinas)
Country : Micronesia
Country : Faroe Islands
Country : France
Country : France
Country : Gabon
Country : Grenada
Country : Georgia
Country : French Guiana
Country : Guernsey
Country : Ghana
Country : Gibraltar
Country : Greenland
Country : The Gambia
Country : Guinea
Country : Guadeloupe
Country : Equatorial Guinea
Country : Greece
Country : South Georgia and the South Sandwich Islands
Country : Guatemala
Country : Guam
Country : Guinea-Bissau
Country : Guyana
Country : Hong Kong (SAR)
Country : Heard Island and McDonald Islands
Country : Honduras
Country : Croatia
Country : Haiti
Country : Hungary
Country : Indonesia
Country : Ireland
Country : Israel
Country : Man
Country : India
Country : British Indian Ocean Territory
Country : Iraq
Country : Iran
Country : Iceland
Country : Italy
Country : Jersey
Country : Jamaica
Country : Jordan
Country : Japan
Country : Kenya
Country : Kyrgyzstan
Country : Cambodia
Country : Kiribati
Country : Comoros
Country : Saint Kitts and Nevis
Country : Korea
Country : Korea
Country : Kuwait
Country : Cayman Islands
Country : Kazakhstan
Country : Laos
Country : Lebanon
Country : Saint Lucia
Country : Liechtenstein
Country : Sri Lanka
Country : Liberia
Country : Lesotho
Country : Lithuania
Country : Luxembourg
Country : Latvia
Country : Libya
Country : Morocco
Country : Monaco
Country : Moldova
Country : Madagascar
Country : Marshall Islands
Country : Macedonia
Country : Mali
Country : Burma
Country : Mongolia
Country : Macao
Country : Northern Mariana Islands
Country : Martinique
Country : Mauritania
Country : Montserrat
Country : Malta
Country : Mauritius
Country : Maldives
Country : Malawi
Country : Mexico
Country : Malaysia
Country : Mozambique
Country : Namibia
Country : New Caledonia
Country : Niger
Country : Norfolk Island
Country : Nigeria
Country : Nicaragua
Country : Netherlands
Country : Norway
Country : Nepal
Country : Nauru
Country : Niue
Country : New Zealand
Country : Oman
Country : Panama
Country : Peru
Country : French Polynesia
Country : Papua New Guinea
Country : Philippines
Country : Pakistan
Country : Poland
Country : Saint Pierre and Miquelon
Country : Pitcairn Islands
Country : Puerto Rico
Country : Palestinian Territory
Country : Portugal
Country : Palau
Country : Paraguay
Country : Qatar
Country : Romania
Country : Russia
Country : Rwanda
Country : Saudi Arabia
Country : Solomon Islands
Country : Seychelles
Country : Sudan
Country : Sweden
Country : Singapore
Country : Saint Helena
Country : Slovenia
Country : Svalbard
Country : Slovakia
Country : Sierra Leone
Country : San Marino
Country : Senegal
Country : Somalia
Country : Suriname
Country : El Salvador
Country : Syria
Country : Swaziland
Country : Turks and Caicos Islands
Country : Chad
Country : French Southern and Antarctic Lands
Country : Togo
Country : Thailand
Country : Tajikistan
Country : Tokelau
Country : Turkmenistan
Country : Tunisia
Country : Tonga
Country : East Timor
Country : Turkey
Country : Trinidad and Tobago
Country : Tuvalu
Country : Taiwan
Country : Tanzania
Country : Ukraine
Country : Uganda
Country : United Kingdom
Country : United States Minor Outlying Islands
Country : United States
Country : Uruguay
Country : Uzbekistan
Country : Holy See (Vatican City)
Country : Saint Vincent and the Grenadines
Country : Venezuela
Country : British Virgin Islands
Country : Virgin Islands
Country : Vietnam
Country : Vanuatu
Country : Wallis and Futuna
Country : Samoa
Country : Yemen
Country : Mayotte
Country : Yugoslavia
Country : South Africa
Country : Zambia
Country : Zimbabwe
Segmentation fault (core dumped)
root#ubuntu:/home/baoky/05AUG-2012-COMPLETED/shell_assn2#
Below is my Client.cpp code
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h> /* for sockaddr_un struct*/
#define DEFAULT_PROTOCOL 0
/* POSIX renames "Unix domain" as "local IPC."
Not all systems define AF_LOCAL and PF_LOCAL (yet). */
#ifndef AF_LOCAL
#define AF_LOCAL AF_UNIX
#endif
#ifndef PF_LOCAL
#define PF_LOCAL PF_UNIX
#endif
using namespace std;
int readLine (int fd, char* str)
{
int n;
do /* Read characters until NULL or end-of-input */
{
}
return (n > 0); /* Return false if end-of-input */
}
void readServer(int fd) //Read Server output
{
char str[20000];
while (readLine (fd, str)) //Read lines till end of input
{
printf("\n%s\n",str);
return;
}
}
/****************************************************************/
int main ()
{
int clientFd, serverLen, result;
struct sockaddr_un serverAddress;
struct sockaddr* serverSockAddrPtr;
serverSockAddrPtr = (struct sockaddr*) &serverAddress;
serverLen = sizeof (serverAddress);
string buffer;
/* Create a socket, bidirectional, default protocol */
clientFd = socket (AF_LOCAL, SOCK_STREAM, DEFAULT_PROTOCOL);
serverAddress.sun_family = AF_LOCAL; /* Server domain */
do /* Loop until a connection is made with the server */
{
result = connect (clientFd, serverSockAddrPtr, serverLen);
if (result == -1) sleep (1); /* Wait and then try again */
}
while (result == -1);
//by here, connection would be established with server
printf("%s\n",'++++++++++++++++++++++++++++++++++++++++++++++++");
printf('\n");
string sendToServer;
while(1)
{
//null the string sendToServer
sendToServer = "";
cin << "Please enter country > ";
//get user input as sendToServer
getline(cout, sendToServer);
if(sendToServer!="")
{
//if not blank
//send to server
write (clientFd, sendToServer.c_str(), strlen (sendToServer.c_str()) + 1);
if ( sendToServer == "END" || sendToServer == "end")
{
//break out of while loop
break;
}//end if
readServer (clientFd); /* Read Server Response */
}//end if not blank
else
{
//print error message in bold red
}
}//end inner while
//if client type end, it will run to here.
close (cfentFd); /* Close the socket */
return 0;
}
Debugging Findout:
I realize if i cut short the countries.txt to about 20 records instead, no segmentation error. what could i do to maybe using a string instead of C string?
how do i use a string instead of char [200]
Thanks! or what could I do to fix the issue
Resolved:
change char to 20000 instead of 2000
When you send a string over a socket ... you do not necessarily get the null terminator unless you explicitly write it in the socket.
I suspect that's what's happening - your strings aren't getting terminated correctly.
IMHO...
STRONG SUGGESTION:
Fire up the debugger, and step through the inner loop in "readLine()". Make sure it's not an infinite loop ;)